package com.iw.adoms.action;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.iw.adoms.entity.OrderMarchandiseDetail;
import com.iw.adoms.service.OrderMarchandiseDetailService;
import com.iw.core.orm.PageData;
import com.iw.core.utils.WebUtils;

@Controller
@RequestMapping("/adoms/orderMarchandiseDetail")
public class OrderMarchandiseDetailAction {
	@Resource
	private OrderMarchandiseDetailService orderMarchandiseDetailService;

	@RequestMapping("/list")
	public ModelMap list(HttpServletRequest request) {
		PageData<OrderMarchandiseDetail> pageData = new PageData<OrderMarchandiseDetail>();
		// 给pageData设置参数
		WebUtils.setPageDataParameter(request, pageData);
		pageData = orderMarchandiseDetailService.find(pageData);

		return new ModelMap(pageData);
	}

	@RequestMapping(value = "/new")
	public String addForm(Model model) {
		return "/adoms/orderMarchandiseDetail/input";
	}

	@RequestMapping(value = "/edit/{id}")
	public String editForm(@PathVariable("id") Integer id, Model model) {
		OrderMarchandiseDetail orderMarchandiseDetail = orderMarchandiseDetailService.find(id);
		model.addAttribute(orderMarchandiseDetail);
		return "/adoms/orderMarchandiseDetail/input";
	}

	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public String save(OrderMarchandiseDetail orderMarchandiseDetail) {
		if (orderMarchandiseDetail.isNew()) {
			orderMarchandiseDetailService.save(orderMarchandiseDetail);
		} else {
			orderMarchandiseDetailService.update(orderMarchandiseDetail);
		}

		return "redirect:/adoms/orderMarchandiseDetail/list";// 重定向
	}

	@RequestMapping(value = "/delete/{id}")
	public String delete(@PathVariable("id") Integer id) {
		orderMarchandiseDetailService.delete(id);
		return "redirect:/adoms/orderMarchandiseDetail/list";// 重定向
	}

	@RequestMapping(value = "/visible/{id}")
	public String visible(@PathVariable("id") Integer id) {
		orderMarchandiseDetailService.visible(id);
		return "redirect:/adoms/orderMarchandiseDetail/list";// 重定向
	}

	@RequestMapping(value = "/unVisible/{id}")
	public String unVisible(@PathVariable("id") Integer id) {
		orderMarchandiseDetailService.unVisible(id);
		return "redirect:/adoms/orderMarchandiseDetail/list";// 重定向
	}

	@InitBinder
	public void InitBinder(WebDataBinder dataBinder) {
		dataBinder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), false));
	}

}
